/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package cifar10.featureextraction;

import java.awt.image.BufferedImage;

/**
 *
 * @author mwh
 */
public class AvgColorFeatureExtractor extends AbstractFixedSizeFeatureExractor implements FixedSizeFeatureExtractor{

    public AvgColorFeatureExtractor() {
        name = "AvgColor";
        size = 4;
        String[] fns = {"alpha", "red", "green", "blue"};
        featuresNames = fns;

    }

    @Override
    public double[] getValues(BufferedImage image) {
        long alpha = 0;
        long red = 0;
        long blue = 0;
        long green = 0;
        for (int y = 0; y < image.getHeight(); y++) {
            for (int x = 0; x < image.getWidth(); x++) {
                int rgb = image.getRGB(x, y);
                alpha += rgb >> 24 & 0xff;
                red += rgb >> 16 & 0xff;
                green += rgb >> 8 & 0xff;
                blue += rgb & 0xff;
            }
        }
        double[] values = {(double) alpha, (double) red, (double) green, (double) blue};
        return values;
    }

}
